package com.zzl.study.nacos.config;

import com.zzl.study.nacos.condition.ConditionalOnNacosMultiDiscoveryEnabled;
import com.zzl.study.nacos.discovery.NacosMultiDiscoveryClient;
import com.zzl.study.nacos.discovery.NacosServiceMultiDiscovery;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Nacos多注册中心服务发现客户端自动配置类
 *
 * @author: zhangzl
 * @date: 2025/7/16 14:22
 * @version: 1.0
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
@ConditionalOnNacosMultiDiscoveryEnabled
@AutoConfigureBefore({SimpleDiscoveryClientAutoConfiguration.class, CommonsClientAutoConfiguration.class})
@AutoConfigureAfter(NacosMultiDiscoveryAutoConfiguration.class)
public class NacosMultiDiscoveryClientAutoConfiguration {

    /**
     * 向Spring容器注入一个Nacos多注册中心服务发现客户端
     *
     * @param nacosServiceMultiDiscovery Nacos多注册中心服务发现对象
     * @return Nacos多注册中心服务发现客户端
     */
    @Bean
    public DiscoveryClient nacosMultiDiscoveryClient(NacosServiceMultiDiscovery nacosServiceMultiDiscovery) {
        return new NacosMultiDiscoveryClient(nacosServiceMultiDiscovery);
    }

}
